package com.gxuwz.medical.domain.pay;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Date;

import com.gxuwz.medical.database.DbUtil;

public class Standard {
	private int year;
	private double money;
	private Date stime;
	private Date etime;
	public boolean hasStandard = false;
	public boolean isOnTime = false;
	
	public Standard(double money, Date stime, Date etime) {
		this.year = Integer.parseInt(new Timestamp(new Date().getTime()).toString().substring(0, 4));
		this.money = money;
		this.stime = stime;
		this.etime = etime;
	}
	public Standard(){
		this.year=Integer.parseInt(new Timestamp(new Date().getTime()).toString().substring(0, 4));
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try{
			conn = new DbUtil().getConn();
			stmt= conn.createStatement();
			String sql = "select * from standard where year="+this.year+"";
			rs = stmt.executeQuery(sql);
			while(rs.next()){
				this.hasStandard = true;
				this.money = rs.getDouble("money");
				Date  stime = new Date(rs.getTimestamp("stime").getTime());
				Date  etime = new Date(rs.getTimestamp("etime").getTime());
				Date nowtime = new Date();
				if(nowtime.after(stime)&&nowtime.before(etime))
					this.isOnTime=true;
			}
			
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	public void add(){
		try{
			DbUtil db = new DbUtil();
			String sql ="insert into standard values('"+this.year+"',"+this.money+",'"+new Timestamp(this.stime.getTime())+"','"+new Timestamp(this.etime.getTime())+"')";
			db.executeUpdate(sql);
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	public void edit() {
		try{
			DbUtil db = new DbUtil();
			String sql ="update standard set money="+this.money+",stime='"+new Timestamp(this.stime.getTime())+"',etime='"+new Timestamp(this.etime.getTime())+"' where year="+this.year+"";
			db.executeUpdate(sql);
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public double getMoney() {
		return money;
	}
	public void setMoney(double money) {
		this.money = money;
	}
	public Date getStime() {
		return stime;
	}
	public void setStime(Date stime) {
		this.stime = stime;
	}
	public Date getEtime() {
		return etime;
	}
	public void setEtime(Date etime) {
		this.etime = etime;
	}
	
	
}
